﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MatStatistic : System.Web.UI.Page
{
    public string Sqlstr = "";
    public string flag = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.dd1Store.Items.Add(new ListItem("--全部--"));
            this.ddlDepartment.Items.Add(new ListItem("--全部--"));
            this.ddlCustomer.Items.Add(new ListItem("--全部--"));
            this.bind();
        }
    }
    public void bind()
    {
        DataSet ds1 = DB.reDs("select Title from tb_BigType where Type='仓库'");
        this.dd1Store.DataSource = ds1;
        dd1Store.DataTextField = "Title";
        dd1Store.DataBind();
        DataSet ds2 = DB.reDs("select Title from tb_BigType where type='部门'");
        ddlDepartment.DataSource = ds2;
        ddlDepartment.DataTextField = "Title";
        ddlDepartment.DataBind();
        DataSet ds3 = DB.reDs("select Name from tb_Enterprise where type1='是'");
        ddlCustomer.DataSource = ds3;
        ddlCustomer.DataTextField = "Name";
        ddlCustomer.DataBind();
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (this.dd1Store.SelectedValue != "--全部--")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.StorePlace='" + this.dd1Store.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and  " + "B.StorePlace='" + this.dd1Store.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        if (this.ddlDepartment.SelectedValue != "--全部--")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.Department='" + this.ddlDepartment.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and  " + "B.Department='" + this.ddlDepartment.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        if (this.ddlCustomer.SelectedValue != "--全部--")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "A.Customer='" + this.ddlCustomer.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and  " + "A.Customer='" + this.ddlCustomer.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        if (this.txtUserName.Text != "")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.UserName='" + this.txtUserName.Text.Trim() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and  " + "B.UserName='" + this.txtUserName.Text.Trim() + "'";
            }
            flag = "1";
        }
        if (this.txtBuyMan.Text != "")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.BuyMan='" + this.txtBuyMan.Text.Trim() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and  " + "B.Buyman='" + this.txtBuyMan.Text.Trim() + "'";
            }
            flag = "1";
        }
        DataSet ds = DB.reDs("select * from tb_GdzcDetails as A inner join tb_Gdzc as B on A.GdzcID=B.GdzcID" + Sqlstr);
        this.gvStatistic.DataSource = ds;
        this.gvStatistic.DataBind();
    }
}
